﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace DynORM.ReferenceObjects
{
    public static class AuxData
    {
        public const string AuxDatasTag = "AuxDatas";
        public const string AuxDataTag = "AuxData";

        public static string CreateFromXml(XmlReader reader)
        {
            string auxData = String.Empty;
            do
            {
                switch (reader.NodeType)
                {
                    //case XmlNodeType.Element:
                    //    {
                    //        if (string.Compare(reader.Name, AuxDataAttr, StringComparison.OrdinalIgnoreCase) == 0)
                    //        {
                    //            bool emptyElement = reader.IsEmptyElement;
                    //            //if (reader.HasAttributes)
                    //            //{
                    //            //    while (reader.MoveToNextAttribute())
                    //            //    {
                    //            //        if (string.Compare(reader.Name, NameAttr, StringComparison.OrdinalIgnoreCase) == 0)
                    //            //            some = reader.Value;
                    //            //    }
                    //            //}
                    //            if (emptyElement)
                    //            {
                    //                auxData = String.Empty;
                    //            }
                    //            //else
                    //            //{ 
                    //            //    auxData = reader.ReadContentAs(typeof(string), null);
                    //            //}
                    //        }
                    //    } break;
                    case XmlNodeType.Text:
                        {
                            auxData = (string)reader.ReadContentAs(typeof(string), null);
                        } break;
                    //case XmlNodeType.EndElement:
                    //    {
                    //    } break;
                    default: continue;
                }
            } while (reader.Read());
            return auxData;
        }

        public static void WriteToXml(XmlWriter writer, string value)
        {
            writer.WriteStartElement(AuxDataTag);
            writer.WriteString(value);
            writer.WriteEndElement();
        }
    }
}
